<?php 

class Sortfunction extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		
		$this->load->helper('form');
		$this->load->model('Jobs');
		$this->load->model('Chats');
		
		$user =& Users::getInstance();
		if ($user->id < 1) {
			// redirect to home
			
		}
	}
	function SortJobIdUpOncoming(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-3);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortJobIdDownOncoming(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortDetailsUpOncoming(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncomingDetails(-3);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortDetailsDownOncoming(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncomingDetails(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	
	
	
	function SortJobIdUpAwaitingQuote(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
				$data['needquote'] = $this->Jobs->getNeedQuote(-3);
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortJobIdDownAwaitingQuote(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
				$data['needquote'] = $this->Jobs->getNeedQuote(-1);
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortDetailsUpAwaitingQuote(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
				$data['needquote'] = $this->Jobs->getNeedQuoteDetails(-3);
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortDetailsDownAwaitingQuote(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
				$data['needquote'] = $this->Jobs->getNeedQuoteDetails(-1);
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	
	function SortJobIdUpAwaitingConfirm(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm(-3);
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortJobIdDownAwaitingConfirm(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortDetailsUpAwaitingConfirm(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirmDetails(-3);
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortDetailsDownAwaitingConfirm(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirmDetails(-1);
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	}
	
	function SortJobIdUpPaymentDue(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-3);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-3, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortJobIdDownPaymentDue(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortDetailsUpPaymentDue(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceListDetails(-3);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceListDetails(-3, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortDetailsDownPaymentDue(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceListDetails(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceListDetails(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	
	function SortJobIdUpComplete(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-3);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortJobIdDownComplete(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortDetailsUpComplete(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompletedDetails(-3);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortDetailsDownComplete(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompletedDetails(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	
	function SortJobIdUpCancel(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-3);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortJobIdDownCancel(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortDetailsUpCancel(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelledDetails(-3);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-3);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	function SortDetailsDownCancel(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
				$data['needquote'] = $this->Jobs->getNeedQuote();
				$data['needquoteCount'] = $this->Jobs->getNeedQuote(-1, true);
				$data['needquotePages'] = $this->Jobs->getPages($data['needquoteCount'], 5);
				$data['needconfirm'] = $this->Jobs->getNeedConfirm();
				$data['needconfirmCount'] = $this->Jobs->getNeedConfirm(-1, true);
				$data['needconfirmPages'] = $this->Jobs->getPages($data['needconfirmCount'], 5);
				$data['oncoming'] = $this->Jobs->getOncoming(-1);
				$data['oncomingCount'] = $this->Jobs->getOncoming(-1, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted(-1);
				$data['completedCount'] = $this->Jobs->getCompletedCount(-1);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelledDetails(-1);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount(-1);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				
				$data['dueCount'] = $this->Jobs->getDueCount(-1);
				$data['overdueCount'] = $this->Jobs->getOverdueCount(-1);
				$data['overduetotal'] = $this->Jobs->getOverduePrice(-1);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList(-1);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList(-1, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList(-1, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
				
				$data['pagingId'] = -1;
				
				$this->load->view('admin-dashboard', $data);
	
	}
	
	
	
	/*////////////////////////////////*/
	/*/         For user             /*/
	/*////////////////////////////////*/
	
	function SortJobIdUpOncomingu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id+1000000);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	function SortJobIdDownOncomingu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	function SortDetailsUpOncomingu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncomingDetails($user->id+1000000);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	function SortDetailsDownOncomingu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncomingDetails($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	function SortJobIdUpCompleteu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id+1000000);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	function SortJobIdDownCompleteu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	function SortDetailsUpCompleteu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompletedDetails($user->id+1000000);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	function SortDetailsDownCompleteu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompletedDetails($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
				
	}
	function SortJobIdUpCancelu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id+1000000);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	function SortJobIdDownCancelu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	function SortDetailsUpCancelu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelledDetails($user->id+1000000);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	function SortDetailsDownCancelu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelledDetails($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	function SortJobIdUpDraftu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id+1000000);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	function SortJobIdDownDraftu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	function SortDetailsUpDraftu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDraftsDetails($user->id+1000000);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	function SortDetailsDownDraftu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDraftsDetails($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	
	function SortJobIdUpPaymentDueu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id+1000000);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id+1000000, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	function SortJobIdDownPaymentDueu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceList($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceList($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	function SortDetailsUpPaymentDueu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceListDetails($user->id+1000000);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceListDetails($user->id+1000000, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	function SortDetailsDownPaymentDueu(){
		$this->load->helper('url');
		$this->load->library('Menu');
		$menu = new Menu;
		$user = &Users::getInstance();		
		$data = $menu->gen();
		$this->load->model('Jobs');
		$data['user'] = $user;
		$this->Jobs->sendMailAlert();
		$this->Jobs->updateJobStatus();
		$regErrors['name'] = false;
				$regErrors['email'] = false;
				$regErrors['emailtaken'] = false;
				$regErrors['password'] = false;
				$regErrors['passwords'] = false;
				$regErrors['phone'] = false;
				$regErrors['address'] = false;
				$data['regErrors'] = $regErrors;
					
				
				
				if ($this->input->post('doregister')) {			
					$errors = $user->updateProfile($user->id,
						$this->input->post('name'), 
						$this->input->post('address'), 
						$this->input->post('phone'), 
						$this->input->post('company_name'));
							
					$data['regErrors'] = $errors;
				}
		
				$data['userinfo'] = $user;
				
				$data['oncoming'] = $this->Jobs->getOncoming($user->id);
				$data['oncomingCount'] = $this->Jobs->getOncoming($user->id, true);
				$data['oncomingPages'] = $this->Jobs->getPages($data['oncomingCount'], 5);
				$data['completed'] = $this->Jobs->getCompleted($user->id);
				$data['completedCount'] = $this->Jobs->getCompletedCount($user->id);
				$data['completedPages'] = $this->Jobs->getPages($data['completedCount'], 5);
				$data['cancelled'] = $this->Jobs->getCancelled($user->id);
				$data['cancelledCount'] = $this->Jobs->getCancelledCount($user->id);
				$data['cancelledPages'] = $this->Jobs->getPages($data['cancelledCount'], 5);
				$data['drafts'] = $this->Jobs->getDrafts($user->id);
				$data['draftsCount'] = $this->Jobs->getDrafts($user->id, true);
				$data['draftsPages'] = $this->Jobs->getPages($data['draftsCount'], 5);
				$data['dueCount'] = $this->Jobs->getDueCount($user->id);
				$data['overdueCount'] = $this->Jobs->getOverdueCount($user->id);
				$data['overduetotal'] = $this->Jobs->getOverduePrice($user->id);
				$data['dueOverduePages'] = $this->Jobs->getPages($data['dueCount'] + $data['overdueCount'], 5);
				
				$data['overdue'] = $this->Jobs->getOverduePriceListDetails($user->id);
				if (count($data['overdue']) < 5 && count($data['overdue']) > 0) {
					$overdueCount = $data['overdueCount'];
					$overduePages = floor($overdueCount/5);
					$overdueLeft = $overdueCount%5;
					
					$duePage = 0 - $overduePages - 1;
					if ($duePage < 0 ) {
						$dueStart = 0;
						$duePage = 0;
					} else {
						$dueStart = ($duePage*5) + $overdueLeft;
					}
					
					$data['due'] = $this->Jobs->getDuePriceListDetails($user->id, $dueStart, 5 - $overdueLeft);
				} elseif (count($data['overdue']) == 0) {
					$data['due'] = $this->Jobs->getDuePriceList($user->id, 0, 5);
				} else {
					$data['due'] = array();
				}
				
				$data['pagingId'] = $user->id;
				$this->load->view('user-dashboard', $data);
	}
	
	
}
